﻿using sys_Print.DataAsset;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace sys_Print.Common
{
    public class EmployeeTemplateSelector : DataTemplateSelector
    {
        public DataTemplate TextBlock { get; set; }
        public DataTemplate TextBox { get; set; }
        public DataTemplate Image { get; set; }
        public DataTemplate QRCode { get; set; }
        public DataTemplate ENNQRCode { get; set; }
        public DataTemplate BarCode { get; set; }
        public DataTemplate DataGrid { get; set; }
        public DataTemplate Border { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item is PrintCanvasModel printCanvasModel)
            {
                // 根据 ControlTypes 属性的值选择要应用的数据模板
                switch (printCanvasModel.ControlType)
                {
                    case "TextBlock":
                        return TextBlock;
                    case "TextBox":
                        return TextBox;
                    case "Image":
                        return Image;
                    case "QRCode":
                        return QRCode;
                    case "ENNQRCode":
                        return ENNQRCode;
                    case "BarCode":
                        return BarCode;
                    case "DataGrid":
                        return DataGrid;
                    case "Border":
                        return Border;
                    default:
                        return TextBlock; // 默认数据模板
                }
            }
            return null;
        }

        public List<string> GetPropertyNames()
        {
            List<string> strings = new List<string>();

            // 获取对象的类型
            Type type = this.GetType();

            // 获取对象的所有属性
            PropertyInfo[] properties = type.GetProperties();

            // 遍历属性并输出属性名称
            foreach (PropertyInfo property in properties)
            {
                strings.Add(property.Name);
            }

            return strings;
        }

    }
}
